package com.zhang.zxx.boot.trans;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;
/**
 * MybatisTransDriver:
 * @author zhangxiaoxiang
 * @since 2025/1/23
 */
@Component
public class MybatisTransDriver implements TransDriver {

  @Override
  public List<?> findByIds(List<? extends Serializable> ids, Class<?> targetClass) {
    try (SqlSession sqlSession = SqlHelper.sqlSession(targetClass)) {
      BaseMapper<?> mapper = SqlHelper.getMapper(targetClass, sqlSession);
      List<?> baseEntities = mapper.selectBatchIds(ids);
      System.err.println("baseEntities = " + baseEntities);
      return baseEntities;
    }
  }

}
